//
//  HLMainTabViewController.m
//  zhuanxian
//
//  Created by zhaoliang chen on 2017/11/16.
//  Copyright © 2017年 huiling. All rights reserved.
//

#import "HLMainTabViewController.h"
#import "HLHomepageViewController.h"
#import "HLContactViewController.h"
#import "HLMessageViewController.h"
#import "HLMeViewController.h"
#import "AppDelegate.h"
#import "HLLoginViewController.h"

@interface HLMainTabViewController ()

@end

@implementation HLMainTabViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tabBar.backgroundColor = [UIColor whiteColor];
    
    HLHomepageViewController *vc1 = [[HLHomepageViewController alloc]init];
    UINavigationController* nav1 = [[UINavigationController alloc]initWithRootViewController:vc1];
    vc1.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:[[UIImage imageNamed:@"hl_tabbar_homepage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"hl_tabbar_homepage_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [self setTabBarItemsTitlesColor:vc1.tabBarItem];
    
    HLMessageViewController *vc2 = [[HLMessageViewController alloc]init];
    UINavigationController* nav2 = [[UINavigationController alloc]initWithRootViewController:vc2];
    vc2.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"消息" image:[[UIImage imageNamed:@"hl_tabbar_message"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"hl_tabbar_message_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [self setTabBarItemsTitlesColor:vc2.tabBarItem];
    
    HLContactViewController *vc3 = [[HLContactViewController alloc]init];
    UINavigationController* nav3 = [[UINavigationController alloc]initWithRootViewController:vc3];
    vc3.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"通讯录" image:[[UIImage imageNamed:@"hl_tabbar_contact"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"hl_tabbar_contact_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [self setTabBarItemsTitlesColor:vc3.tabBarItem];
    
    HLMeViewController *vc4 = [[HLMeViewController alloc]init];
    UINavigationController* nav4 = [[UINavigationController alloc]initWithRootViewController:vc4];
    vc4.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:[[UIImage imageNamed:@"hl_tabbar_me"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"hl_tabbar_me_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [self setTabBarItemsTitlesColor:vc4.tabBarItem];
    
    self.viewControllers = @[nav1, nav2, nav3, nav4];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginoutNotification:) name:@"loginoutNotification" object:nil];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setTabBarItemsTitlesColor:(UITabBarItem *)item {
    [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                  [UIColor grayColor], NSForegroundColorAttributeName,[UIFont systemFontOfSize:10.0],NSFontAttributeName,
                                  nil] forState:UIControlStateNormal];
    [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                  MainColor, NSForegroundColorAttributeName,[UIFont systemFontOfSize:10.0],NSFontAttributeName,
                                  nil] forState:UIControlStateSelected];
}

- (void)loginoutNotification:(NSNotification*)sender {
    AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    HLLoginViewController* vc = [[HLLoginViewController alloc]init];
    appDelegate.window.rootViewController = vc;
    [self dismissViewControllerAnimated:NO completion:nil];
}

@end
